package com.maila.xiaoaoschool.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.maila.xiaoaoschool.R;
import com.maila.xiaoaoschool.entity.FoodEntity;
import com.maila.xiaoaoschool.widget.SectionedBaseAdapter;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/9/26.
 */

public class ShopDetailsAdapter extends SectionedBaseAdapter {
    Context context;
    List<FoodEntity.category> foodbeanList;

    public ShopDetailsAdapter(Context context) {
        this.context = context;
        foodbeanList = new ArrayList<>();
    }

    public List<FoodEntity.category> getFoodbeanList() {
        return foodbeanList;
    }

    public void setFoodbeanList(List<FoodEntity.category> foodbeanList) {
        this.foodbeanList = foodbeanList;
        notifyDataSetChanged();
    }

    public void addFoodbeanList(List<FoodEntity.category> foodbeanList) {
        this.foodbeanList.addAll(foodbeanList);
        notifyDataSetChanged();
    }

    public void remove(int position) {
        this.foodbeanList.remove(position);
        notifyDataSetChanged();
    }

    @Override
    public FoodEntity.category.foodbean getItem(int section, int position) {
        return foodbeanList.get(section).getFoodbeans().get(position);
    }

    @Override
    public long getItemId(int section, int position) {
        return 0;
    }

    @Override
    public int getSectionCount() {
        return foodbeanList.size();
    }

    @Override
    public int getCountForSection(int section) {
        return foodbeanList.get(section).getFoodbeans().size();
    }

    @Override
    public View getItemView(int section, int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_shop_detail, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
            AutoUtils.autoSize(convertView);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvShopName.setText(foodbeanList.get(section).getFoodbeans().get(position).getDishes());
        return convertView;
    }

    @Override
    public View getSectionHeaderView(int section, View convertView, ViewGroup parent) {
        ViewHolder1 holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_shop_detail_header, parent, false);
            holder = new ViewHolder1(convertView);
            convertView.setTag(holder);
            AutoUtils.autoSize(convertView);
        } else {
            holder = (ViewHolder1) convertView.getTag();
        }
        holder.tvCategoryName.setText(foodbeanList.get(section).getName());
        return convertView;
    }




    static class ViewHolder {
        @BindView(R.id.iv_shop)
        ImageView ivShop;
        @BindView(R.id.tv_shop_name)
        TextView tvShopName;
        @BindView(R.id.tv_xiaoliang)
        TextView tvXiaoliang;
        @BindView(R.id.tv_fee)
        TextView tvFee;
        @BindView(R.id.btn_reduce)
        ImageView btnReduce;
        @BindView(R.id.tv_num)
        TextView tvNum;
        @BindView(R.id.btn_plus)
        ImageView btnPlus;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    static  class ViewHolder1 {
        @BindView(R.id.tv_category_name)
        TextView tvCategoryName;

        ViewHolder1(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
